import java.awt.Color;
import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * 
 * @author Adam and Terry
 *
 */
public class Road extends Path2D.Double {

	private static final long serialVersionUID = 741713763308816772L;
	private String name;
	private String delimiter;
	private Color[] colours_array;
	private int[] thickness_array;
	private Color colour;
	private int thickness;
	private boolean solid; 
	
	/**
	 * 
	 * @param name
	 * @param delimiter
	 */
	public Road(String name, String delimiter) {
		this.name = "";
		this.delimiter = delimiter;
		this.solid = true; 
		this.thickness =0;
		// colours array 
		colours_array = new Color[6];
		colours_array[0] = Color.green;
		colours_array[1] = Color.black;
		colours_array[2] = Color.red;
		colours_array[3] = Color.orange;
		colours_array[4] = new Color(139,69,19);
		colours_array[5] =   new Color(139,69,19); 
		// thickness array 
		thickness_array = new int[6];
		thickness_array[0] = 16;
		thickness_array[1] = 12;
		thickness_array[2] = 8;
		thickness_array[3] = 6;
		thickness_array[4] = 4;
		thickness_array[5] = 4;
	}
	
	/**
	 * 
	 * @return get the road name 
	 */

	public String getName() {
		return name;
	}
	
	/**
	 * 
	 * @return get the road colour 
	 */
	
	public Color getColour(){
		return this.colour;
	}
	
	/**
	 * 
	 * @return get the road thickness
	 */
	
	public int getThickness()
	{
		return this.thickness;
	}
	
	/**
	 * 
	 * @return get the road solid 
	 */
	
	public boolean getSolid()
	{
		return this.solid;
	}
	
	/**
	 * Reads lon-lat data. Stops when line "END" is read.
	 * 
	 * @param input
	 *            open file which has just read the number
	 * @throws IoException
	 *             or subclass if something goes wrong
	 */
	public void read(BufferedReader input, String line) throws IOException {
		//String line = input.readLine();
		Point2D.Double pt1 = null;
		Point2D.Double pt2 = null;
		
		while (!line.equalsIgnoreCase("end")) {
			String[] parts = line.split(this.delimiter);
			name = parts[0];
			
			if(parts.length > 1){
				double x1 = java.lang.Double.parseDouble(parts[1]);
				double y1 = java.lang.Double.parseDouble(parts[2]);
				double x2 = java.lang.Double.parseDouble(parts[3]);
				double y2 = java.lang.Double.parseDouble(parts[4]);
				
				pt1 = new Point2D.Double(x1, y1);
				pt2 = new Point2D.Double(x2, y2);
			
				this.colour = colours_array[new Integer(parts[5])];
				this.thickness = thickness_array[new Integer(parts[6])];
				
				if(parts[6].equals("5")){
					this.solid = false; 
				}
				append(new Line2D.Double(pt1, pt2), true);
							
				line = input.readLine();
			}
		}	
	}
}
